Skip to content

Conversation

WendellAdriel
Copy link
Contributor

Overview

Inspired by the implementation I did for Http::batch: #56946
I'm adding the implementation for Process::batch.

Example

$results = Process::batch(fn (Batch $batch) => [
    $batch->as('first')->command('bash import-1.sh');
    $batch->as('second')->command('bash import-2.sh');
    $batch->as('third')->command('bash import-3.sh');
])->before(function (Batch $batch) {
    // This runs before the first process is executed.
})->progress(function (Batch $batch, int|string $key, ProcessResult $result) {
    // This runs after each successful process from the Batch.
})->catch(function (Batch $batch, int|string $key, ProcessResult|ProcessFailedException|ProcessTimedOutException $result) {
    // This runs after each failed process from the Batch.
})->then(function (Batch $batch, array $results) {
    // This runs ONLY IF all the processes from the Batch are successful.
})->finally(function (Batch $batch, array $results) {
    // This runs after all the processes from the Batch finish.
})->run();

Deferred Batches

This also supports the defer() as added later on this PR: #57387

$results = Process::batch(fn (Batch $batch) => [
    $batch->as('first')->command('bash import-1.sh');
    $batch->as('second')->command('bash import-2.sh');
    $batch->as('third')->command('bash import-3.sh');
})->then(function (Batch $batch, array $results) {
    // This runs ONLY IF all the processes from the Batch are successful.
})->defer();

@taylorotwell
Copy link
Member

I'll probably wait on this one. I want to drive it via real world usage, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants